package com.example.administrator.myapplication4.util;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.StringBuilderPrinter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2020/12/14.
 */

public class GetJsonDataUtil {

    public String getJson(Context context, String filename){
        //第一步 创建数据缓冲器（空间）
        StringBuilder stringBuilder = new StringBuilder();
        //第二步 获取本地数据资源管理器

            AssetManager assetManager = context.getAssets();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    assetManager.open(filename)));
            String line;
            while ((line = reader.readLine())!= null){
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stringBuilder.toString();
    }
}
